package com.biz.primus.auth.config;

import com.biz.primus.model.sso.auth.config.ServiceAuthorityConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;

/**
 * Created by younger on 17/11/10.
 */
@Configuration
@Order(2)
public class AuthConfig {
    private static final String DEFAULT_SUPER_ADMIN_ID = "admin";

    private final Environment environment;

    @Autowired
    public AuthConfig(Environment environment) {
        this.environment = environment;
    }

    @Bean
    public ServiceAuthorityConfig serviceAuthorityConfig(){
        String adminId = environment.getProperty("biz.authority.super-admin-id");

        return new ServiceAuthorityConfig(adminId==null ? DEFAULT_SUPER_ADMIN_ID : adminId);
    }
}
